package gare.vente;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;


public class BilleterieImpl implements Billeterie {
   
   /* private int nbTicketsDispo;
    @Override
    public void reservation(int nbPlaces) {
	Reserveur t = new Reserveur();
	//t.setDaemon(true);
	t.start();
    }

    @Override
    public void ajouterTickets(int nbTicketsAJout) {
	nbTicketsDispo += nbTicketsAJout;
	notifyAll();
    }
    
    public synchronized void acheter(int nb){
	if (nbTicketsDispo >= nb) {	    
	    nbTicketsDispo -= nb;
	} else {
	    try {
		wait();
	    } catch (InterruptedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	    }
	}
    }
    
    public static void main(String args[]){
	try {
        	System.out.println("Installing security manager...");
        	if (System.getSecurityManager() == null) {
        	    System.setSecurityManager(new SecurityManager());
        	}
        	System.out.println("done");
        	System.out.println("Creating the remotely accessible BilleterieImpl (and the stub)...");
        	Billeterie billeterie = new BilleterieImpl();
        	Billeterie stub = (Billeterie)UnicastRemoteObject.exportObject(billeterie,0);
        	
        	System.out.println("done...");
        	System.out.println("Registrering the stub...");
        	Registry registry = LocateRegistry.createRegistry(1055);
        	registry.rebind("billet", stub);
        	System.out.println("done...");
	} catch (RemoteException e) {
	    // TODO Auto-generated catch block
	    e.printStackTrace();
	}
    }*/

}